<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录</title>
</head>

<body>

  用户名：<input type="text" name="" id="username">===
  密码:<input type="text" name="" id="password">
  <button id="loginBtn">登录</button>

  <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.js"></script>
  <script>
    /* 步骤分析
    1、给loginBtn按钮绑定点击事件
    2、获取表单值
    3、发送请求
    4、提示登录成功
    */
    const loginBtn = document.querySelector('#loginBtn')
    const usernameDom = document.querySelector('#username')
    const passwordDom = document.querySelector('#password')
    loginBtn.addEventListener('click', () => {
      const username = usernameDom.value
      const password = passwordDom.value
      axios({
        url: 'http://hmajax.itheima.net/api/login',
        method: "post",
        data: {
          username,
          password
        }
      }).then(res => {
        console.log(res, 8);
        if (res.data.code == 10000) {
          alert(res.data.message)
        }
      }).catch(err => {
        console.log(err, 88);
      })

    })
  </script>
</body>

</html>